#pragma once

#ifndef __CORE_Mutex_H__
#define __CORE_Mutex_H__

#include "FLOW_core/namespace.h"

namespace CORE
{
	class CMutex
	{
	private:
		//==================================== METHODS ========================

		//! Forbid copy constructor
		CMutex( const CMutex& ar_mutex );

		//! Forbid assignment
		CMutex& operator = ( const CMutex& ar_mutex );

	public:
		//==================================== METHODS ========================

		//! Default contructor
		CMutex( );

		//! Destructor
		~CMutex( );

		//! Try to get the ownership of the mutex, blocking the thread if necessary
		void Lock( void );

		//! Release the ownership of the mutex
		void Unlock( void );

		//! Initializes Mutex system
		static bool_t Initialize( void );

		//! Shutdowns Mutex system
		static bool_t Shutdown( void );
	};

	/*!
	 * \brief Helper class to apply a mutex in a scope
	 *
	 * Helper class to apply a mutex in a scope.
	 */
	class CMutexLocker
	{
	private:
		//=========================== DATA MEMBERS ============================

		//! Mutex to operate on
		CMutex*		m_p_mutex;
	public:
		//============================= METHODS ===============================

		//! Default constructor
		CMutexLocker( CMutex& ap_mutex );

		//! Destructor
		~CMutexLocker( );

	private:
		//============================= METHODS ===============================

		//! Forbid copy construction
		CMutexLocker( const CMutexLocker& ar_mutex_locker );

		//! Forbid assignment
		CMutexLocker& operator = ( const CMutexLocker& ar_mutex_locker );
	};

} //namespace CORE
#endif